package com.jwsoft.manager.core.integration.impl;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.extra.servlet.ServletUtil;
import cn.hutool.poi.excel.ExcelWriter;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.bifang.engine.assistant.core.annotation.ApiService;
import com.bifang.engine.assistant.core.annotation.OpApi;
import com.bifang.engine.assistant.core.annotation.SaveOplog;
import com.bifang.engine.assistant.core.enums.AuTypeEnum;
import com.bifang.engine.assistant.core.enums.AuthStatusEnum;
import com.bifang.engine.assistant.core.enums.BoolEnum;
import com.bifang.engine.assistant.core.enums.FuncTypeEnum;
import com.bifang.engine.assistant.core.exception.AppException;
import com.bifang.engine.assistant.core.utils.SessionUtil;
import com.bifang.engine.data.core.util.PagerUtil;
import com.bifang.module.base.common.vo.dict.DictAreaVO;
import com.bifang.module.base.common.vo.dict.SelectVO;
import com.bifang.module.base.common.vo.excel.ExcelModelVO;
import com.bifang.module.base.common.vo.excel.ExcelVO;
import com.bifang.module.base.core.helper.DictHelper;
import com.bifang.module.base.core.helper.ExcelCommonHelper;
import com.bifang.module.base.core.integration.DictIntegration;
import com.bifang.module.system.core.integration.impl.ExcelIntegrationImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jwsoft.manager.common.enums.EnrollStatusFormalEnum;
import com.jwsoft.manager.common.enums.StudentTjDictEnum;
import com.jwsoft.manager.common.enums.TjTypeEnum;
import com.jwsoft.manager.common.vo.cache.EduOperationCacheDetailVO;
import com.jwsoft.manager.common.vo.cache.EduOperationCacheQueryVO;
import com.jwsoft.manager.common.vo.eduSchool.EduSchoolVO;
import com.jwsoft.manager.common.vo.eduStudentTj.*;
import com.jwsoft.manager.core.dao.model.EduStudentEnroll;
import com.jwsoft.manager.core.dao.model.EduStudentTj;
import com.jwsoft.manager.core.dao.service.EduSchoolService;
import com.jwsoft.manager.core.dao.service.EduStudentEnrollService;
import com.jwsoft.manager.core.dao.service.EduStudentTjService;
import com.jwsoft.manager.core.integration.EduStudentTjIntegration;
import com.jwsoft.manager.core.integration.EduSystemConfigIntegration;
import com.jwsoft.manager.core.util.EduEnrollClearCacheHelper;
import com.jwsoft.manager.core.util.EduHelper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;

import javax.servlet.http.HttpServletResponse;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 学生调剂信息业务实现类
 *
 * @author zhiyuan
 * @since 2023-03-13
 */
@ApiService(funcCode = "studentTj", title = "学生调剂信息")
public class EduStudentTjIntegrationImpl implements EduStudentTjIntegration {

    @Autowired
    public EduStudentTjService eduStudentTjService;
    @Autowired
    private EduStudentEnrollService eduStudentEnrollService;
    @Autowired
    private DictHelper dictHelper;
    @Autowired
    private EduSchoolService eduSchoolService;
    @Autowired
    private EduSystemConfigIntegration eduSystemConfigIntegration;
    @Autowired
    private EduHelper eduHelper;
    @Autowired
    private DictIntegration dictIntegration;
    @Autowired
    public ExcelIntegrationImpl excelIntegration;
    @Value("${spring.servlet.multipart.location}")
    private String tempPath;

    @Autowired
    ExcelCommonHelper excelCommonHelper;
    @Autowired
    private EduEnrollClearCacheHelper eduEnrollClearCacheHelper;

    @Override
    @OpApi(funcCode = "studentTj0001", title = "学生调剂信息分页查询", funcType = FuncTypeEnum.query)
    public PageInfo<EduStudentTjVO> getList(EduStudentTjQueryVO vo) {
        // 开启分页
        if (vo.getPageNum() == null || vo.getPageSize() == null) {
            //如果不传入分页参数，默认最大取1000条
            vo.setPageNum(1);
            vo.setPageSize(20);
        }
        if (vo.getYear() == null) {
            vo.setYear(eduHelper.thisYear());
        }
        if (ObjectUtils.isEmpty(vo.getAreaCode())) {
            vo.setAreaCode(SessionUtil.getAreaCode());
        }
        QueryWrapper<EduStudentTj> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(EduStudentTj::getYear, vo.getYear())
                .eq(StringUtils.isNotBlank(vo.getAspirationType()), EduStudentTj::getAspirationType, vo.getAspirationType())
                .eq(StringUtils.isNotBlank(vo.getFromSchoolId()), EduStudentTj::getFromSchoolId, vo.getFromSchoolId())
                .eq(StringUtils.isNotBlank(vo.getTjType()), EduStudentTj::getTjType, vo.getTjType())
                .eq(StringUtils.isNotBlank(vo.getToSchoolId()), EduStudentTj::getToSchoolId, vo.getToSchoolId())
                .eq(StringUtils.isNotBlank(vo.getAreaCode()), EduStudentTj::getAreaCode, vo.getAreaCode())
                .eq(StringUtils.isNotBlank(vo.getAuthStatus()), EduStudentTj::getAuthStatus, vo.getAuthStatus())
                .eq(StringUtils.isNotBlank(vo.getCurrentFlag()), EduStudentTj::getCurrentFlag, vo.getCurrentFlag())
                .eq(StringUtils.isNotBlank(vo.getConfigName()), EduStudentTj::getConfigName, vo.getConfigName())
                .eq(StringUtils.isNotBlank(vo.getConfigTypeName()), EduStudentTj::getConfigTypeName, vo.getConfigTypeName())
                .orderByAsc(EduStudentTj::getToSchoolId, EduStudentTj::getConfigName, EduStudentTj::getRegisterDate, EduStudentTj::getAspirationType);
        PageHelper.startPage(vo.getPageNum(),vo.getPageSize());
        List<EduStudentTj> list = eduStudentTjService.list(queryWrapper);
        if (CollectionUtils.isEmpty(list)) {
            // 判断是否为空，为空则返回空参数
            return PagerUtil.createEmptyPagerInfo(vo.getPageNum(), vo.getPageSize());
        }
        // 不为空则获取分页结果
        PageInfo<EduStudentTj> pageInfo = new PageInfo<>(list);
        // 返回参数需要通过common层的vo实体类，用该方法可以批量转换
        List<EduStudentTjVO> resultList = Convert.toList(EduStudentTjVO.class, pageInfo.getList());
        // 转义数据字典值
        // dictHelper.valueToName(resultList, Arrays.asList(DemoDictEnum.values()));
        return PagerUtil.parsePagerVo(resultList, pageInfo);
    }

    @Override
    @OpApi(funcCode = "studentTj0002", title = "学生调剂信息根据主键查询详情", funcType = FuncTypeEnum.query)
    public EduStudentTjVO getById(EduStudentTjKeyVO vo) {
        EduStudentTj entity = eduStudentTjService.getById(vo.getStudentTjId());
        if (ObjectUtils.isEmpty(entity)) {
            throw new AppException("查询不到详细信息!");
        }
        EduStudentTjVO result = Convert.convert(EduStudentTjVO.class, entity);
        return result;
    }
    /** 保存前统一校验*/
    @Override
    @OpApi(funcCode = "studentTj0003", title = "学生调剂信息保存前校验", funcType = FuncTypeEnum.other ,checkPrivilege = BoolEnum.FALSE)
    public void checkSave(EduStudentTjVO vo) {
        //主键为空为新增校验

        //主键不为空为修改校验
    }

    @Override
    @OpApi(funcCode = "studentTj0004", title = "学生调剂信息新增", funcType = FuncTypeEnum.insert)
    @SaveOplog(
            operationType = "studentTj0004",
            operationName = "学生调剂信息新增",
            dataType = "studentTjId",
            auType = AuTypeEnum.OTHER)
    @Transactional
    public EduStudentTjVO add(EduStudentTjVO vo) {
        //保存前校验
        checkSave(vo);
        //保存数据
        EduStudentTj entity = Convert.convert(EduStudentTj.class, vo);
        eduStudentTjService.save(entity);
        //将主键设置回vo使操作日志可以取到
        vo.setStudentTjId(entity.getStudentTjId());
        return vo;
    }

    @Override
    @OpApi(funcCode = "studentTj0005", title = "学生调剂信息修改", funcType = FuncTypeEnum.update)
    @SaveOplog(
            operationType = "studentTj0005",
            operationName = "学生调剂信息修改",
            dataType = "studentTjId",
            auType = AuTypeEnum.OTHER)
    @Transactional
    public EduStudentTjVO edit(EduStudentTjVO vo) {
        if (ObjectUtils.isEmpty(vo.getStudentTjId())) {
            throw new AppException("传入需要修改的主键不能为空!");
        }
        EduStudentTj oldEntity = eduStudentTjService.getById(vo.getStudentTjId());
        if (ObjectUtils.isEmpty(oldEntity)) {
            throw new AppException("查询不到需要修改的信息!");
        }
        //保存前校验
        checkSave(vo);
        //保存数据
        EduStudentTj entity = Convert.convert(EduStudentTj.class, vo);
        eduStudentTjService.updateById(entity);
        return vo;
    }

    @Override
    @OpApi(funcCode = "studentTj0006", title = "学生调剂信息根据主键删除", funcType = FuncTypeEnum.delete)
    @SaveOplog(
            operationType = "studentTj0006",
            operationName = "学生调剂信息删除",
            dataType = "studentTjId",
            auType = AuTypeEnum.OTHER)
    @Transactional
    public void del(EduStudentTjKeyVO vo) {
        if (ObjectUtils.isEmpty(vo.getStudentTjId())) {
            throw new AppException("传入需要删除的数据主键不能为空!");
        }
        EduStudentTj entity = eduStudentTjService.getById(vo.getStudentTjId());
        if (ObjectUtils.isEmpty(entity)) {
            throw new AppException("未找到需要删除的信息!");
        }
        eduStudentTjService.removeById(vo.getStudentTjId());
        if(StringUtils.isNotBlank(entity.getStudentEnrollId())){
            EduStudentEnroll eduStudentEnroll=eduStudentEnrollService.getById(entity.getStudentEnrollId());
            eduEnrollClearCacheHelper.clearCacheMyEnroll(eduStudentEnroll.getIdcard());
            eduEnrollClearCacheHelper.clearCacheMyEnroll(eduStudentEnroll.getFatherIdcard());
            eduEnrollClearCacheHelper.clearCacheMyEnroll(eduStudentEnroll.getMotherIdcard());
            eduEnrollClearCacheHelper.clearCacheMyEnrollPre(eduStudentEnroll.getIdcard());
            eduEnrollClearCacheHelper.clearCacheMyEnrollPre(eduStudentEnroll.getFatherIdcard());
            eduEnrollClearCacheHelper.clearCacheMyEnrollPre(eduStudentEnroll.getMotherIdcard());
        }

    }

    @Override
    @Transactional
    @OpApi(funcCode = "studentTj0007", title = "家长端调剂申请", funcType = FuncTypeEnum.insert)
    @SaveOplog(
            operationType = "studentTj0007",
            operationName = "家长端调剂申请",
            dataType = "studentEnrollId",
            auType = AuTypeEnum.OTHER)
    public void saveApply(EduStudentTjApplyVO vo) {
        if (StringUtils.isBlank(vo.getStudentEnrollId())) {
            throw new AppException("报名id不能为空");
        }
        if (CollectionUtils.isEmpty(vo.getToSchoolIdList())) {
            throw new AppException("调剂志愿学校不能为空");
        }
        EduStudentEnroll eduStudentEnroll = eduStudentEnrollService.getById(vo.getStudentEnrollId());
        if (eduStudentEnroll == null) {
            throw new AppException("报名数据不存在");
        }
        EduOperationCacheQueryVO queryVO = new EduOperationCacheQueryVO();
        queryVO.setOperating("YW059");
        queryVO.setAreaCode(eduStudentEnroll.getAreaCode());
        queryVO.setYear(eduStudentEnroll.getYear());
        queryVO.setClassify("2");
        EduOperationCacheDetailVO bmOption = eduSystemConfigIntegration.getEduOperationOne(queryVO);
        if (bmOption == null) {
            throw new AppException("调剂申请尚未开始");
        } else {
            if (!bmOption.isFlag()) {
                if ("1".equalsIgnoreCase(bmOption.getType())) {
                    throw new AppException("调剂申请尚未开始");
                } else if ("2".equalsIgnoreCase(bmOption.getType())) {
                    throw new AppException("调剂申请已结束");
                }
            }
        }
        QueryWrapper<EduStudentTj> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(EduStudentTj::getStudentEnrollId, vo.getStudentEnrollId())
                .eq(EduStudentTj::getFromSchoolId, eduStudentEnroll.getSchoolId())
                .eq(EduStudentTj::getCurrentFlag, BoolEnum.TRUE.getType());
        EduStudentTj eduStudentCheck = eduStudentTjService.getOne(queryWrapper, false);
        if (eduStudentCheck != null) {
            if (AuthStatusEnum.NODO.getType().equalsIgnoreCase(eduStudentCheck.getAuthStatus())) {
                throw new AppException("已申请，请耐心等待审核");
            } else if (AuthStatusEnum.YES.getType().equalsIgnoreCase(eduStudentCheck.getAuthStatus())) {
                throw new AppException("已完成调剂");
            }
            eduStudentCheck.setCurrentFlag(BoolEnum.FALSE.getType());
            eduStudentTjService.updateById(eduStudentCheck);
        }

        List<EduStudentTj> saveList = new ArrayList<>();
        int i = 1;
        if (StringUtils.isBlank(vo.getFollowFlag())){
            vo.setFollowFlag(BoolEnum.FALSE.getType());
        }
        if (StringUtils.isNotBlank(vo.getFollowSchoolId())){
            EduSchoolVO eduSchoolVO=eduSchoolService.getDetail(vo.getFollowSchoolId());
            if (eduSchoolVO!=null){
                vo.setFollowSchoolName(eduSchoolVO.getSchoolName());
            }
        }
        for (String toSchoolId : vo.getToSchoolIdList()) {
            EduStudentTj eduStudentTj = new EduStudentTj();
            eduStudentTj.setStudentTjId(IdUtil.simpleUUID());
            eduStudentTj.setStudentEnrollId(vo.getStudentEnrollId());
            eduStudentTj.setFullName(eduStudentEnroll.getFullName());
            eduStudentTj.setIdcard(eduStudentEnroll.getIdcard());
            eduStudentTj.setFromSchoolId(eduStudentEnroll.getSchoolId());
            eduStudentTj.setFromSchoolName(eduStudentEnroll.getSchoolName());
            eduStudentTj.setAreaCode(eduStudentEnroll.getAreaCode());
            eduStudentTj.setConfigName(eduStudentEnroll.getConfigName());
            eduStudentTj.setConfigTypeName(eduStudentEnroll.getConfigTypeName());
            eduStudentTj.setRegisterDate(eduStudentEnroll.getRegisterDate());
            eduStudentTj.setQysj(eduStudentEnroll.getQysj());
            eduStudentTj.setCbTotal(eduStudentEnroll.getCbTotal());
            eduStudentTj.setTjType(TjTypeEnum.jz.getType());
            eduStudentTj.setToSchoolId(toSchoolId);
            EduSchoolVO eduSchoolVO = eduSchoolService.getDetail(toSchoolId);
            eduStudentTj.setToSchoolName(eduSchoolVO != null ? eduSchoolVO.getSchoolName() : "");
            eduStudentTj.setYear(eduStudentEnroll.getYear());
            eduStudentTj.setAspirationType(String.valueOf(i));
            eduStudentTj.setStudentEnrollStatus(eduStudentEnroll.getEnrollStatus());
            eduStudentTj.setStudentAdmitFlag(eduStudentEnroll.getAdmitFlag());
            eduStudentTj.setStudentAuthStatus(eduStudentEnroll.getAuthStatus());
            eduStudentTj.setAuthStatus(AuthStatusEnum.NODO.getType());
            eduStudentTj.setFollowFlag(vo.getFollowFlag());
            eduStudentTj.setFollowFullName(vo.getFollowFullName());
            eduStudentTj.setFollowIdcard(vo.getFollowIdcard());
            eduStudentTj.setFollowSchoolName(vo.getFollowSchoolName());
            eduStudentTj.setFollowSchoolId(vo.getFollowSchoolId());
            eduStudentTj.setFollowSchoolClass(vo.getFollowSchoolClass());
            eduStudentTj.setFollowType(vo.getFollowType());
            if (i == 1) {
                eduStudentTj.setCurrentFlag(BoolEnum.TRUE.getType());
            } else {
                eduStudentTj.setCurrentFlag(BoolEnum.FALSE.getType());
            }
            i = i + 1;
            saveList.add(eduStudentTj);
        }

        eduStudentTjService.saveBatch(saveList);

        eduEnrollClearCacheHelper.clearCacheMyEnroll(eduStudentEnroll.getIdcard());
        eduEnrollClearCacheHelper.clearCacheMyEnroll(eduStudentEnroll.getFatherIdcard());
        eduEnrollClearCacheHelper.clearCacheMyEnroll(eduStudentEnroll.getMotherIdcard());
        eduEnrollClearCacheHelper.clearCacheMyEnrollPre(eduStudentEnroll.getIdcard());
        eduEnrollClearCacheHelper.clearCacheMyEnrollPre(eduStudentEnroll.getFatherIdcard());
        eduEnrollClearCacheHelper.clearCacheMyEnrollPre(eduStudentEnroll.getMotherIdcard());

    }


    @Override
    @OpApi(funcCode = "studentTj0008", title = "学生调剂分页查询（管理端/学校端）接口", funcType = FuncTypeEnum.query)
    public PageInfo<EduStudentTjVO> queryStudentTj(EduStudentTjQueryVO vo) {
        // 开启分页
        if (vo.getPageNum() == null || vo.getPageSize() == null) {
            //如果不传入分页参数，默认最大取1000条
            vo.setPageNum(1);
            vo.setPageSize(20);
        }
        List<String> areaCodeList = new ArrayList<>();
        if (ObjectUtils.isEmpty(vo.getAreaCode())){
            List<SelectVO> selectVOList = dictIntegration.getDistrictByOrg(new DictAreaVO());
            areaCodeList = selectVOList.stream()
                    .map(SelectVO::getDictKey)
                    .collect(Collectors.toList());
            String sessionAreaCode = SessionUtil.getAreaCode();
            if (!areaCodeList.contains(sessionAreaCode)) {
                areaCodeList.add(sessionAreaCode);
            }
        }else {
            areaCodeList.add(vo.getAreaCode());
        }
        if (CollectionUtils.isEmpty(areaCodeList)){
            throw new AppException("必须传入行政区划");
        }
        if (ObjectUtils.isEmpty(vo.getYear())){
            vo.setYear(eduHelper.thisYear());
        }
        if (ObjectUtils.isEmpty(vo.getPermission())){
            throw new AppException("permission不能为空！");
        }
        if (ObjectUtils.isEmpty(vo.getAreaCode())) {
            vo.setAreaCode(SessionUtil.getAreaCode());
        }
        QueryWrapper<EduStudentTj> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(EduStudentTj::getYear, vo.getYear())
                .eq(StringUtils.isNotBlank(vo.getFullName()), EduStudentTj::getFullName, vo.getFullName())
                .eq(StringUtils.isNotBlank(vo.getIdcard()),EduStudentTj::getIdcard,vo.getIdcard())
                .eq(StringUtils.isNotBlank(vo.getAuthStatus()),EduStudentTj::getAuthStatus,vo.getAuthStatus())
                .in(EduStudentTj::getAreaCode,areaCodeList)
                .eq(StringUtils.isNotBlank(vo.getConfigTypeName()),EduStudentTj::getConfigTypeName,vo.getConfigTypeName())
                .eq(StringUtils.isNotBlank(vo.getConfigName()),EduStudentTj::getConfigName,vo.getConfigName())
                .eq(StringUtils.isNotBlank(vo.getAspirationType()),EduStudentTj::getAspirationType,vo.getAspirationType())
                .eq(StringUtils.isNotBlank(vo.getTjType()),EduStudentTj::getTjType,vo.getTjType())
                .orderByAsc(EduStudentTj::getAspirationType,EduStudentTj::getToSchoolId,EduStudentTj::getConfigName,EduStudentTj::getRegisterDate,EduStudentTj::getQysj,EduStudentTj::getCreateTime);
        //表示是管理员权限
        if (vo.getPermission() != null && vo.getPermission().equals("1")){
            queryWrapper.lambda()
                    .eq(StringUtils.isNotBlank(vo.getFromSchoolId()),EduStudentTj::getFromSchoolId,vo.getFromSchoolId())
                    .eq(StringUtils.isNotBlank(vo.getToSchoolId()),EduStudentTj::getToSchoolId,vo.getToSchoolId());
        }
        //是学校端，调入学校才能看到
        else if (vo.getPermission() != null && vo.getPermission().equals("0")) {
            EduSchoolVO eduSchoolVO=eduSchoolService.getDetail(SessionUtil.getSessionInfo().getOrgId());
            if(eduSchoolVO==null){
                throw new AppException("您的账号不是学校账号，不能操作此功能");
            }
            queryWrapper.lambda()
                    .eq(EduStudentTj::getCurrentFlag,BoolEnum.TRUE.getType())
                    .eq(EduStudentTj::getToSchoolId,SessionUtil.getSessionInfo().getOrgId());
        }
        queryWrapper.lambda()
                .orderByAsc(
                        EduStudentTj::getIdcard,
                        EduStudentTj::getAspirationType,
                        EduStudentTj::getToSchoolId,
                        EduStudentTj::getConfigName,
                        EduStudentTj::getRegisterDate
                );
        PageHelper.startPage(vo.getPageNum(),vo.getPageSize());
        List<EduStudentTj> list = eduStudentTjService.list(queryWrapper);

        if (CollectionUtils.isEmpty(list)) {
            // 判断是否为空，为空则返回空参数
            return PagerUtil.createEmptyPagerInfo(vo.getPageNum(), vo.getPageSize());
        }

        List<String> studentEnrollIdList = list.stream().map(EduStudentTj::getStudentEnrollId).collect(Collectors.toList());
        QueryWrapper<EduStudentEnroll> enrollQueryWrapper = new QueryWrapper<>();
        enrollQueryWrapper.lambda().in(EduStudentEnroll::getStudentEnrollId,studentEnrollIdList);
        List<EduStudentEnroll> enrollList = eduStudentEnrollService.list(enrollQueryWrapper);
        Map<String,EduStudentEnroll> enrollMap = enrollList.stream().collect(Collectors.toMap(EduStudentEnroll::getStudentEnrollId, a -> a,(k1,k2)->k1));


        // 不为空则获取分页结果
        PageInfo<EduStudentTj> pageInfo = new PageInfo<>(list);
        // 返回参数需要通过common层的vo实体类，用该方法可以批量转换
        List<EduStudentTjVO> resultList = Convert.toList(EduStudentTjVO.class, pageInfo.getList());
        for (EduStudentTjVO tjVO : resultList) {
            EduStudentEnroll enroll = enrollMap.get(tjVO.getStudentEnrollId());
            if(enroll!=null){
                tjVO.setFatherName(enroll.getFatherName());
                tjVO.setFatherCellphone(enroll.getFatherCellphone());
                tjVO.setMotherName(enroll.getMotherName());
                tjVO.setMotherCellphone(enroll.getMotherCellphone());
                tjVO.setHouseId(enroll.getHouseId());
                tjVO.setHouseAdreess(enroll.getHouseAdreess());
                tjVO.setHouseholdId(enroll.getHouseholdId());
            }
        }
        // 转义数据字典值
         dictHelper.valueToName(resultList, Arrays.asList(StudentTjDictEnum.values()));
        return PagerUtil.parsePagerVo(resultList, pageInfo);
    }

    @OpApi(funcCode = "studentTj0009", title = "学生调剂数据审核", funcType = FuncTypeEnum.update)
    @Override
    @Transactional
    public void auditStudentTj(EduStudentTjVO vo) {
        if (StringUtils.isEmpty(vo.getStudentTjId())){
            throw new AppException("调剂主键不能为空");
        }
        EduStudentTj studentTj = eduStudentTjService.getById(vo.getStudentTjId());
        if (ObjectUtils.isEmpty(studentTj)){
            throw new AppException("调剂数据不存在，请刷新后重试！");
        }
        //审核前数据校验
        Boolean clearFlag = auditCheck(vo, studentTj);

        if (clearFlag){
            QueryWrapper<EduStudentTj> queryWrapper = new QueryWrapper<>();
            queryWrapper.lambda()
                    .eq(EduStudentTj::getIdcard,vo.getIdcard())
                    .eq(EduStudentTj::getYear,vo.getYear())
                    .ge(EduStudentTj::getAspirationType,studentTj.getAspirationType())
                    .orderByAsc(EduStudentTj::getAspirationType);
            List<EduStudentTj> list = eduStudentTjService.list(queryWrapper);
            for (EduStudentTj eduStudentTj : list) {
                eduStudentTj.setAuthStatus(AuthStatusEnum.BH.getType());
                eduStudentTj.setAuthRemarks("该学生已被其他学校录取，无法调剂，系统设置调剂无效!");
                eduStudentTj.setAuthUserId(SessionUtil.getUserId());
                eduStudentTj.setAuthTime(new Date());
                eduStudentTj.setUpdateName(SessionUtil.getUserId());
                eduStudentTj.setUpdateTime(new Date());
                eduStudentTjService.updateById(eduStudentTj);
            }
            return;
        }
        //用户审核通过
        if(AuthStatusEnum.YES.getType().equals(vo.getAuthStatus())){
            //其他调剂设置无效
            QueryWrapper<EduStudentTj> tjQuery = new QueryWrapper<>();
            tjQuery.lambda()
                    .eq(EduStudentTj::getYear,vo.getYear())
                    .eq(EduStudentTj::getIdcard,vo.getIdcard())
                    .gt(EduStudentTj::getAspirationType,studentTj.getAspirationType())
                    .orderByAsc(EduStudentTj::getAspirationType);
            List<EduStudentTj> list = eduStudentTjService.list(tjQuery);
            UpdateWrapper<EduStudentTj> tjUpdateWrapper = new UpdateWrapper<>();
            if (!CollectionUtils.isEmpty(list)){
                for (EduStudentTj eduStudentTj : list) {
                    tjUpdateWrapper.lambda()
                            .eq(EduStudentTj::getStudentTjId,eduStudentTj.getStudentTjId())
                            .eq(EduStudentTj::getYear,eduHelper.thisYear())
                            .set(EduStudentTj::getAuthStatus,AuthStatusEnum.BH.getType())
                            .set(EduStudentTj::getAuthRemarks,"其他数据审核通过，系统设置驳回审核")
                            .set(EduStudentTj::getAuthTime,new Date())
                            .set(EduStudentTj::getAuthUserId,SessionUtil.getSessionInfo().getUserId())
                            .set(EduStudentTj::getUpdateTime,new Date())
                            .set(EduStudentTj::getUpdateName,SessionUtil.getSessionInfo().getUserId());
                    eduStudentTjService.update(tjUpdateWrapper);
                    tjUpdateWrapper.clear();
                }
            }
            //修改当前数据状态
            tjUpdateWrapper.lambda()
                    .eq(EduStudentTj::getStudentTjId,vo.getStudentTjId())
                    .eq(EduStudentTj::getYear,eduHelper.thisYear())
                    .set(EduStudentTj::getAuthStatus,vo.getAuthStatus())
                    .set(EduStudentTj::getAuthRemarks,vo.getAuthRemarks())
                    .set(EduStudentTj::getAuthTime,new Date())
                    .set(EduStudentTj::getAuthUserId,SessionUtil.getSessionInfo().getUserId())
                    .set(EduStudentTj::getUpdateName,SessionUtil.getSessionInfo().getUserId())
                    .set(EduStudentTj::getUpdateTime,new Date());
            eduStudentTjService.update(tjUpdateWrapper);

            //修改报名表数据
            EduStudentEnroll eduStudentEnroll = eduStudentEnrollService.getById(studentTj.getStudentEnrollId());
            EduSchoolVO eduSchool = eduSchoolService.getDetail(studentTj.getToSchoolId());
            UpdateWrapper<EduStudentEnroll> enrollUpdateWrapper = new UpdateWrapper<>();
            enrollUpdateWrapper.lambda()
                    .eq(EduStudentEnroll::getYear,eduHelper.thisYear())
                    .eq(EduStudentEnroll::getStudentEnrollId,studentTj.getStudentEnrollId())
                    .set(EduStudentEnroll::getSchoolId,studentTj.getToSchoolId())
                    .set(EduStudentEnroll::getSchoolName,studentTj.getToSchoolName())
                    .set(EduStudentEnroll::getBasis,"从"+eduStudentEnroll.getSchoolName()+"调剂到"+studentTj.getToSchoolName())
                    .set(EduStudentEnroll::getDeployFlag,BoolEnum.TRUE.getType())
                    .set(EduStudentEnroll::getStreet,eduSchool.getStreet())
                    .set(EduStudentEnroll::getEnrollStatus, EnrollStatusFormalEnum.lq.getType())
                    .set(EduStudentEnroll::getAuthStatus,AuthStatusEnum.YES.getType())
                    .set(EduStudentEnroll::getAdmitFlag,BoolEnum.TRUE.getType())
                    .set(EduStudentEnroll::getAdmitRemarks,"学校调剂审核录取")
                    .set(EduStudentEnroll::getUpdateName,SessionUtil.getSessionInfo().getUserId())
                    .set(EduStudentEnroll::getUpdateTime,new Date());
            if (ObjectUtils.isEmpty(eduStudentEnroll.getFromSchoolId())){
                enrollUpdateWrapper.lambda()
                        .set(EduStudentEnroll::getFromSchoolId,eduStudentEnroll.getSchoolId())
                        .set(EduStudentEnroll::getFromSchoolName,eduStudentEnroll.getSchoolName());
            }
            eduStudentEnrollService.update(enrollUpdateWrapper);

        } else if (AuthStatusEnum.NO.getType().equals(vo.getAuthStatus())) {
            //用户审核不通过
            UpdateWrapper<EduStudentTj> tjUpdateWrapper = new UpdateWrapper<>();
            tjUpdateWrapper.lambda()
                    .eq(EduStudentTj::getStudentTjId,vo.getStudentTjId())
                    .eq(EduStudentTj::getYear,eduHelper.thisYear())
                    .set(EduStudentTj::getCurrentFlag,BoolEnum.FALSE.getType())
                    .set(EduStudentTj::getAuthStatus,vo.getAuthStatus())
                    .set(EduStudentTj::getAuthRemarks,vo.getAuthRemarks())
                    .set(EduStudentTj::getAuthTime,new Date())
                    .set(EduStudentTj::getAuthUserId,SessionUtil.getSessionInfo().getUserId())
                    .set(EduStudentTj::getUpdateName,SessionUtil.getSessionInfo().getUserId())
                    .set(EduStudentTj::getUpdateTime,new Date());
            eduStudentTjService.update(tjUpdateWrapper);

            QueryWrapper<EduStudentTj> tjQuery = new QueryWrapper<>();
             tjQuery.lambda()
                    .eq(EduStudentTj::getYear,vo.getYear())
                    .eq(EduStudentTj::getIdcard,vo.getIdcard())
                    .gt(EduStudentTj::getAspirationType,studentTj.getAspirationType())
                    .orderByAsc(EduStudentTj::getAspirationType);

             //审核不通过将后一条数据当前状态设置为是
            EduStudentTj eduStudentTj = eduStudentTjService.getOne(tjQuery, false);
            if (!ObjectUtils.isEmpty(eduStudentTj)){
                eduStudentTj.setCurrentFlag(BoolEnum.TRUE.getType());
                eduStudentTj.setUpdateTime(new Date());
                eduStudentTj.setUpdateName(SessionUtil.getUserId());
                eduStudentTjService.updateById(eduStudentTj);
            }
        }else{
            throw new AppException("审核状态不符合要求，无法进行审核");
        }

        if(StringUtils.isNotBlank(studentTj.getStudentEnrollId())){
            EduStudentEnroll eduStudentEnroll=eduStudentEnrollService.getById(studentTj.getStudentEnrollId());
            eduEnrollClearCacheHelper.clearCacheMyEnroll(eduStudentEnroll.getIdcard());
            eduEnrollClearCacheHelper.clearCacheMyEnroll(eduStudentEnroll.getFatherIdcard());
            eduEnrollClearCacheHelper.clearCacheMyEnroll(eduStudentEnroll.getMotherIdcard());
            eduEnrollClearCacheHelper.clearCacheMyEnrollPre(eduStudentEnroll.getIdcard());
            eduEnrollClearCacheHelper.clearCacheMyEnrollPre(eduStudentEnroll.getFatherIdcard());
            eduEnrollClearCacheHelper.clearCacheMyEnrollPre(eduStudentEnroll.getMotherIdcard());
        }
    }

    @OpApi(funcCode = "studentTj0010", title = "家长调剂数据驳回到待审核（管理员）", funcType = FuncTypeEnum.update)
    @Override
    @Transactional
    public void rejectedToReview(EduStudentTjRejectedVO vo) {
        if (!BoolEnum.TRUE.getType().equalsIgnoreCase(vo.getPermission())){
            throw new AppException("管理员模块才能进行数据驳回!");
        }

        if (!AuthStatusEnum.NODO.getType().equalsIgnoreCase(vo.getAuthStatus())){
            throw new AppException("传入审核的状态有误！");
        }
        EduStudentTj studentTj = eduStudentTjService.getById(vo.getStudentTjId());
        if (ObjectUtils.isEmpty(studentTj)){
            throw new AppException("驳回的调剂数据有误，请刷新后重试！");
        }
        if (!TjTypeEnum.jz.getType().equals(studentTj.getTjType())){
            throw new AppException("该调剂数据不是家长端申请，不能进行驳回！");
        }
        if (!studentTj.getYear().equals(eduHelper.thisYear())){
            throw new AppException("驳回的数据不是当前年度数据，不能进行操作！");
        }
        if (!studentTj.getAuthStatus().equalsIgnoreCase(AuthStatusEnum.YES.getType())){
            throw new AppException("审核通过的数据才能进行驳回！");
        }
        if (!BoolEnum.TRUE.getType().equals(studentTj.getCurrentFlag())){
            throw new AppException("驳回的数据不是可操作的数据，无法进行操作！");
        }

        //修改当前数据
        UpdateWrapper<EduStudentTj> tjUpdateWrapper = new UpdateWrapper<>();
        tjUpdateWrapper.lambda()
                .eq(EduStudentTj::getStudentTjId,vo.getStudentTjId())
                .set(EduStudentTj::getAuthStatus,vo.getAuthStatus())
                .set(EduStudentTj::getAuthRemarks,null)
                .set(EduStudentTj::getAuthTime,new Date())
                .set(EduStudentTj::getAuthUserId,SessionUtil.getUserId())
                .set(EduStudentTj::getUpdateTime,new Date())
                .set(EduStudentTj::getUpdateName,SessionUtil.getUserId());
        eduStudentTjService.update(tjUpdateWrapper);

        //其他志愿调剂需要恢复
        QueryWrapper<EduStudentTj> tjQuery = new QueryWrapper<>();
        tjQuery.lambda()
                .eq(EduStudentTj::getYear,eduHelper.thisYear())
                .eq(EduStudentTj::getIdcard,studentTj.getIdcard())
                .gt(EduStudentTj::getAspirationType,studentTj.getAspirationType())
                .orderByAsc(EduStudentTj::getAspirationType);
        List<EduStudentTj> list = eduStudentTjService.list(tjQuery);
        if (!CollectionUtils.isEmpty(list)){
            for (EduStudentTj eduStudentTj : list) {
                tjUpdateWrapper.clear();
                tjUpdateWrapper.lambda()
                        .eq(EduStudentTj::getStudentTjId,eduStudentTj.getStudentTjId())
                        .eq(EduStudentTj::getYear,eduHelper.thisYear())
                        .set(EduStudentTj::getAuthStatus,AuthStatusEnum.NODO.getType())
                        .set(EduStudentTj::getAuthRemarks,null)
                        .set(EduStudentTj::getAuthTime,new Date())
                        .set(EduStudentTj::getAuthUserId,SessionUtil.getSessionInfo().getUserId())
                        .set(EduStudentTj::getUpdateTime,new Date())
                        .set(EduStudentTj::getUpdateName,SessionUtil.getSessionInfo().getUserId());
                eduStudentTjService.update(tjUpdateWrapper);
            }
        }

        //回退报名表数据,数据恢复
        EduStudentEnroll eduStudentEnroll = eduStudentEnrollService.getById(studentTj.getStudentEnrollId());
        if (ObjectUtils.isEmpty(eduStudentEnroll)){
            throw new AppException("报名表数据不存在，请联系管理员进行核对！");
        }
        EduSchoolVO eduSchool = eduSchoolService.getDetail(studentTj.getFromSchoolId());
        if (studentTj.getFromSchoolId().equalsIgnoreCase(eduStudentEnroll.getFromSchoolId())
            &&
            studentTj.getFromSchoolName().equalsIgnoreCase(eduStudentEnroll.getFromSchoolName())){
            eduStudentEnroll.setSchoolId(studentTj.getFromSchoolId());
            eduStudentEnroll.setSchoolName(studentTj.getFromSchoolName());
            eduStudentEnroll.setBasis(null);
            eduStudentEnroll.setFromSchoolId(null);
            eduStudentEnroll.setFromSchoolName(null);
            eduStudentEnroll.setStreet(eduSchool.getStreet());
            eduStudentEnroll.setDeployFlag(BoolEnum.FALSE.getType());
            eduStudentEnroll.setUpdateName(SessionUtil.getUserId());
            eduStudentEnroll.setUpdateTime(new Date());
            if (StringUtils.isNotBlank(studentTj.getStudentEnrollStatus())){
                eduStudentEnroll.setEnrollStatus(studentTj.getStudentEnrollStatus());
            }
            if (StringUtils.isNotBlank(studentTj.getStudentAuthStatus())){
                eduStudentEnroll.setAuthStatus(studentTj.getStudentAuthStatus());
            }
            if (StringUtils.isNotBlank(studentTj.getStudentAdmitFlag())){
                eduStudentEnroll.setAdmitFlag(studentTj.getStudentAdmitFlag());
            }
            //修改报名表数据
            eduStudentEnrollService.updateById(eduStudentEnroll);
        }else{
            throw new AppException("数据有误，请联系管理员进行核对！");
        }

        if(StringUtils.isNotBlank(studentTj.getStudentEnrollId())){
            eduEnrollClearCacheHelper.clearCacheMyEnroll(eduStudentEnroll.getIdcard());
            eduEnrollClearCacheHelper.clearCacheMyEnroll(eduStudentEnroll.getFatherIdcard());
            eduEnrollClearCacheHelper.clearCacheMyEnroll(eduStudentEnroll.getMotherIdcard());
            eduEnrollClearCacheHelper.clearCacheMyEnrollPre(eduStudentEnroll.getIdcard());
            eduEnrollClearCacheHelper.clearCacheMyEnrollPre(eduStudentEnroll.getFatherIdcard());
            eduEnrollClearCacheHelper.clearCacheMyEnrollPre(eduStudentEnroll.getMotherIdcard());
        }

    }

    @OpApi(funcCode = "studentTj0011", title = "撤回学校调剂数据（管理员）", funcType = FuncTypeEnum.update)
    @Override
    @Transactional
    public void withdrawSchoolTj(EduStudentTjRejectedVO vo) {
        if (!BoolEnum.TRUE.getType().equalsIgnoreCase(vo.getPermission())){
            throw new AppException("管理员模块才能进行撤回调剂数据!");
        }
        if (!AuthStatusEnum.BH.getType().equalsIgnoreCase(vo.getAuthStatus())){
            throw new AppException("传入审核的状态有误！");
        }
        EduStudentTj studentTj = eduStudentTjService.getById(vo.getStudentTjId());
        if (ObjectUtils.isEmpty(studentTj)){
            throw new AppException("驳回的调剂数据有误，请刷新后重试！");
        }
        if (!studentTj.getYear().equals(eduHelper.thisYear())){
            throw new AppException("撤回的数据不是当前年度数据，不能进行操作！");
        }
        if (!studentTj.getAuthStatus().equalsIgnoreCase(AuthStatusEnum.YES.getType())){
            throw new AppException("审核通过的调剂数据才能进行撤回！");
        }
        if (!TjTypeEnum.xx.getType().equals(studentTj.getTjType())){
            throw new AppException("该调剂数据不是学校端申请，不能进行驳回！");
        }
        if (!BoolEnum.TRUE.getType().equals(studentTj.getCurrentFlag())){
            throw new AppException("驳回的数据不是可操作的数据，无法进行操作！");
        }

        //修改当前数据
        UpdateWrapper<EduStudentTj> tjUpdateWrapper = new UpdateWrapper<>();
        tjUpdateWrapper.lambda()
                .eq(EduStudentTj::getStudentTjId,vo.getStudentTjId())
                .set(EduStudentTj::getAuthStatus,vo.getAuthStatus())
                .set(EduStudentTj::getUpdateTime,new Date())
                .set(EduStudentTj::getUpdateName,SessionUtil.getUserId());
        eduStudentTjService.update(tjUpdateWrapper);


        //回退报名表数据,数据恢复
        EduStudentEnroll eduStudentEnroll = eduStudentEnrollService.getById(studentTj.getStudentEnrollId());
        if (ObjectUtils.isEmpty(eduStudentEnroll)){
            throw new AppException("报名表数据不存在，请联系管理员进行核对！");
        }
        EduSchoolVO eduSchool = eduSchoolService.getDetail(studentTj.getFromSchoolId());
        //将报名表修改的数据进行回退
        eduStudentEnroll.setSchoolId(studentTj.getFromSchoolId());
        eduStudentEnroll.setSchoolName(studentTj.getFromSchoolName());
        eduStudentEnroll.setStreet(eduSchool.getStreet());
        eduStudentEnroll.setUpdateName(SessionUtil.getUserId());
        eduStudentEnroll.setUpdateTime(new Date());
        if (eduStudentEnroll.getFromSchoolId().equalsIgnoreCase(studentTj.getFromSchoolId())){
            eduStudentEnroll.setFromSchoolName(null);
            eduStudentEnroll.setFromSchoolId(null);
            eduStudentEnroll.setDeployFlag(BoolEnum.FALSE.getType());
            eduStudentEnroll.setBasis(null);
        }else {
            eduStudentEnroll.setDeployFlag(BoolEnum.TRUE.getType());
            eduStudentEnroll.setBasis("撤回调剂数据到"+eduSchool.getSchoolName());
        }
        if (StringUtils.isNotBlank(studentTj.getStudentEnrollStatus())){
            eduStudentEnroll.setEnrollStatus(studentTj.getStudentEnrollStatus());
        }
        if (StringUtils.isNotBlank(studentTj.getStudentAuthStatus())){
            eduStudentEnroll.setAuthStatus(studentTj.getStudentAuthStatus());
        }
        if (StringUtils.isNotBlank(studentTj.getStudentAdmitFlag())){
            eduStudentEnroll.setAdmitFlag(studentTj.getStudentAdmitFlag());
        }

        eduStudentEnrollService.updateById(eduStudentEnroll);
        if(StringUtils.isNotBlank(studentTj.getStudentEnrollId())){
            eduEnrollClearCacheHelper.clearCacheMyEnroll(eduStudentEnroll.getIdcard());
            eduEnrollClearCacheHelper.clearCacheMyEnroll(eduStudentEnroll.getFatherIdcard());
            eduEnrollClearCacheHelper.clearCacheMyEnroll(eduStudentEnroll.getMotherIdcard());
            eduEnrollClearCacheHelper.clearCacheMyEnrollPre(eduStudentEnroll.getIdcard());
            eduEnrollClearCacheHelper.clearCacheMyEnrollPre(eduStudentEnroll.getFatherIdcard());
            eduEnrollClearCacheHelper.clearCacheMyEnrollPre(eduStudentEnroll.getMotherIdcard());
        }
    }

    @Override
    @OpApi(funcCode = "studentTj0012", title = "学校调剂情况统计", funcType = FuncTypeEnum.query)
    public PageInfo<EduStudentTjStatisticsVO> queryTjStatistics(EduStudentTjQueryVO vo) {
        // 开启分页
        if (vo.getPageNum() == null || vo.getPageSize() == null) {
            //如果不传入分页参数，默认最大取1000条
            vo.setPageNum(1);
            vo.setPageSize(50);
        }
        if (ObjectUtils.isEmpty(vo.getAreaCode())) {
            vo.setAreaCode(SessionUtil.getAreaCode());
        }
        if (vo.getYear() == null) {
            vo.setYear(eduHelper.thisYear());
        }
        PageHelper.startPage(vo.getPageNum(),vo.getPageSize());
        List<EduStudentTjStatisticsVO> list = eduStudentTjService.queryTjStatistics(vo);
        if (CollectionUtils.isEmpty(list)) {
            // 判断是否为空，为空则返回空参数
            return PagerUtil.createEmptyPagerInfo(vo.getPageNum(), vo.getPageSize());
        }
        // 不为空则获取分页结果
        PageInfo<EduStudentTjStatisticsVO> pageInfo = new PageInfo<>(list);
        for(EduStudentTjStatisticsVO statisticsVO:pageInfo.getList()){
            if (StringUtils.isNotBlank(statisticsVO.getAreaCode())) {
                statisticsVO.setAreaName(dictHelper.getAreaNameByCode(statisticsVO.getAreaCode()));
            }
        }
        return pageInfo;
    }

    @Override
    public void exportTjData(EduStudentTjQueryVO vo, HttpServletResponse response) {
        ExcelVO excelVO = new ExcelVO();
        excelVO.setModelCode(vo.getModelCode());
        ExcelModelVO excelModelVO = excelIntegration.getModel(excelVO);

        String destFilePath = this.tempPath + "/" + IdUtil.fastSimpleUUID() + "." + excelModelVO.getExcelType();
        int pageNum = 1;
        setData(excelModelVO, null, destFilePath, vo, pageNum);
        String fileName = vo.getFileName();
        if (StringUtils.isBlank(fileName)) {
            fileName =
                    excelModelVO.getModelName()
                            + "_"
                            + DateUtil.format(DateUtil.date(), DatePattern.PURE_DATETIME_PATTERN)
                            + "."
                            + (StringUtils.isBlank(excelModelVO.getExcelType())
                            ? "xls"
                            : excelModelVO.getExcelType());
        }
        File file = FileUtil.file(destFilePath);
        BufferedInputStream in = null;
        try {
            in = FileUtil.getInputStream(file);
            ServletUtil.write(response, in, "application/octet-stream;charset=utf-8", fileName);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            FileUtil.del(destFilePath);
        }
    }

    private void setData(ExcelModelVO excelModelVO, ExcelWriter excelWriter, String destFilePath, EduStudentTjQueryVO vo, int pageNum) {
        vo.setPageNum(pageNum);
        vo.setPageSize(500);
        boolean closeFlag = false;
        try {
            PageInfo<EduStudentTjVO> pageInfo = queryStudentTj(vo);
            String total = String.valueOf(pageInfo.getTotal());
            List<Object> list = new ArrayList<>();
            if (!CollectionUtils.isEmpty(pageInfo.getList())) {
                for (EduStudentTjVO studentVO : pageInfo.getList()) {
                    list.add(studentVO);
                }
            }
            if (pageNum == 1) {
                if (excelWriter == null) {
                    excelWriter = excelCommonHelper.createExcelWriter(excelModelVO, destFilePath, Integer.parseInt(total));
                }
                excelCommonHelper.writeBean(excelWriter, list);
            } else {
                excelCommonHelper.writeBean(excelWriter, list);
            }
            if (pageInfo.isHasNextPage()) {
                pageNum = pageNum + 1;
                setData(excelModelVO, excelWriter, destFilePath, vo, pageNum);
            } else {
                closeFlag = true;
            }
        } catch (AppException appEx) {
            throw appEx;
        } catch (Exception e) {
            throw new AppException("调用自定义写入服务异常:" + e.getMessage());
        } finally {
            if (closeFlag && excelWriter != null) {
                excelWriter.close();
            }
        }
    }

    /**
     * 审核前数据校验
     * @param vo
     * @return
     */
    private Boolean auditCheck(EduStudentTjVO vo,EduStudentTj studentTj ) {
        Boolean clearFlag = false;
        if (ObjectUtils.isEmpty(vo.getYear())){
            vo.setYear(eduHelper.thisYear());
        }
        if (ObjectUtils.isEmpty(vo.getIdcard())){
            throw new AppException("学生身份证不能为空！");

        }
        if (ObjectUtils.isEmpty(vo.getAuthStatus())){
            throw new AppException("审核状态不能为空!");
        }
        if (ObjectUtils.isEmpty(vo.getAuthRemarks())){
            throw new AppException("审核意见不能为空!");
        }
        if (ObjectUtils.isEmpty(studentTj)){
            throw new AppException("调剂数据不存在，请刷新后重试！");
        }
        if (!studentTj.getYear().equals(eduHelper.thisYear())){
            throw new AppException("审核的数据不是可操作数据，无法进行操作！");
        }
        //current_flag = 1 and tj_type = 1 才可以进行审核
        if (!BoolEnum.TRUE.getType().equals(studentTj.getCurrentFlag())){
            throw new AppException("审核的数据不是可操作数据，请联系管理员！");
        }
        if(!TjTypeEnum.jz.getType().equals(studentTj.getTjType())){
            throw new AppException("审核的数据的类型不是家长端调剂，无法进行审核！");
        }
        if (!"0".equals(studentTj.getAuthStatus())){
            throw new AppException("该数据已处理，无法进行审核！");
        }

        //查询报名表，是否有已录取的数据
        QueryWrapper<EduStudentEnroll> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda()
                .eq(EduStudentEnroll::getYear,vo.getYear())
                .eq(EduStudentEnroll::getIdcard,vo.getIdcard())
                .eq(EduStudentEnroll::getEnrollStatus,"2")
                .eq(EduStudentEnroll::getAuthStatus,AuthStatusEnum.YES.getType())
                .eq(EduStudentEnroll::getAdmitFlag,"1");
        if (eduStudentEnrollService.count(queryWrapper) > 0){
            clearFlag = true;
        }

        return clearFlag;
    }

}
